package com.sailfish.springbootdemo.dao.db1;

import com.sailfish.springbootdemo.common.DB1TableName;
import com.sailfish.springbootdemo.pojo.db1.EmailRecord;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface EmailRecordDao {

    /**
     * 查询所有
     */
    @Results(id = "emailRecordResultMap", value = {
            @Result(column = "email_id", property = "emailId", jdbcType = JdbcType.INTEGER),
            @Result(column = "email_result", property = "emailResult", jdbcType = JdbcType.INTEGER),
            @Result(column = "email_json", property = "emailJson", jdbcType = JdbcType.VARCHAR),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "fail_reason", property = "failReason", jdbcType = JdbcType.VARCHAR),
    })
    @Select("<script>" +
            "select * from " + DB1TableName.EMAIL_RECORD + " where 1 = 1 " +
            "<if test='emailResult != null and emailResult != \"\" '>" +
            " and email_result = #{emailResult}" +
            "</if>" +
            " order by create_time desc" +
            "<if test='begin != null and pageSize != null and pageSize != \"\" '>" +
            " limit #{begin}, #{pageSize}" +
            "</if>" +
            "</script>")
    List<EmailRecord> getAllEmailRecord(@Param("emailResult") Integer emailResult,@Param("begin") Integer begin, @Param("pageSize") Integer pageSize);

    /**
     * 新增
     */
    @Insert("insert into " + DB1TableName.EMAIL_RECORD + " (email_result,email_json,create_time,fail_reason) values (#{emailRecord.emailResult},#{emailRecord.emailJson},#{emailRecord.createTime},#{emailRecord.failReason})")
    Integer addEmailRecord(@Param("emailRecord")EmailRecord emailRecord);
}
